/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 */

import { appRoot, initByProject, initExecuteCommand } from '../../base/src/common/common';
import { runHvigor } from '@ohos/hvigor-ohos-plugin/test/e2e-test/common/common';

describe('test parallel execute.', () => {
  test('test parallel project execute successful', async () => {
    await initByProject('parallel-test', async (rootProject) => {
      const commands = initExecuteCommand({
        tasks: 'default'
      });
      const result = await runHvigor(rootProject, commands);

      expect(result.stdout).toContain('doing clean2 work1...');
      expect(result.stdout).toContain('doing clean work1...');
      expect(result.stdout).toContain('doing clean work2...');
      expect(result.stdout).toContain('doing clean work3...');
      expect(result.stdout).toContain('test work[0] done.');
      expect(result.stdout).toContain('clean2 work[1] done.');
      expect(result.stdout).toContain('clean work[2] done.');
      expect(result.stdout).toContain('clean work[3] done.');
      expect(result.stdout).toContain('clean work[4] done.');

      expect(result.stdout).toContain('BUILD SUCCESSFUL');
    }, undefined, appRoot(__dirname));
  });

  test('test parallel project execute successful with --noParallel', async () => {
    await initByProject('parallel-test', async (rootProject) => {

      const commandWithNoParallel = initExecuteCommand({
        tasks: 'default',
        noParallel: true
      });

      const resultWithNoParallel = await runHvigor(rootProject, commandWithNoParallel);

      expect(resultWithNoParallel.stdout).toContain(
        'Task module1:test\'s work:0 will not be executed in worker pool.');
      expect(resultWithNoParallel.stdout).toContain('BUILD SUCCESSFUL');

    }, undefined, appRoot(__dirname));
  });
});
